# Maintainer: yumetodo <yume-wikijp@live.jp>

_realname=skyr-url
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.7.5
pkgrel=1
pkgdesc="A C++ library that implements the WhatWG URL specification"
arch=('any')
url='https://github.com/cpp-netlib/url'
license=('BSL-1.0')
depends=("${MINGW_PACKAGE_PREFIX}-tl-expected")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-gcc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-catch"
  "${MINGW_PACKAGE_PREFIX}-nlohmann-json"
  "${MINGW_PACKAGE_PREFIX}-fmt"
)
source=("url-v1.7.5.tar.gz::https://github.com/cpp-netlib/url/archive/v1.7.5.tar.gz")
sha256sums=("aa2f475cdcb445fa2e858ee5af6cd352be42ed66c41bfad88a904fcf97e9ee23")

prepare() {
  mkdir -p "url-$pkgver/build"
  cd "url-$pkgver"
  # patch catch.hpp path to catch2/catch.hpp
  find -type f -exec sed -i 's/<catch.hpp>/<catch2\/catch.hpp>/g' {} \;
}

build() {
  cd "url-$pkgver/build"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_CXX_FLAGS="-Werror=maybe-uninitialized" \
    -DCMAKE_BUILD_TYPE="Release" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ..

  make
}

check() {
  cd "url-$pkgver/build"
  ctest
}

package() {
  cd "url-$pkgver/build"
  make DESTDIR="$pkgdir/" install
}
